//
//  Connect.h
//  IOSDemo
//
//  Created by wang on 13-1-24.
//  Copyright (c) 2013年 wang. All rights reserved.
//

#ifndef __IOSDemo__Connect__
#define __IOSDemo__Connect__

#include <iostream>
#import "jid.h"
#include "registration.h" // gloox headers
#include "client.h"
#include "connectionlistener.h"
#include "presencehandler.h"
#include "messagesessionhandler.h"
#include "messageeventhandler.h"
#include "messageeventfilter.h"
#include "chatstatehandler.h"
#include "chatstatefilter.h"
#include "disco.h"
#include "message.h"
#include "lastactivity.h"
#include "loghandler.h"
#include "logsink.h"
#include "connectiontcpclient.h"
#include "connectionsocks5proxy.h"
#include "connectionhttpproxy.h"
#include "messagehandler.h"
#include "gloox.h"
#include "loghandler.h"
#include "vcardhandler.h"
#include "vcardmanager.h"
#include "vcard.h"
#include "rostermanager.h"
#include "rosteritem.h"

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

#import "WhLoginViewController.h"

using namespace gloox;

class Connect : public ConnectionListener, LogHandler,
   	MessageHandler, ChatStateHandler,
	VCardHandler
{
public:
    Connect();
    ~Connect();
    void login(const char* username, const char* password, const char* domain);
	virtual void onConnect();
	virtual bool onTLSConnect(const CertInfo& info);
	virtual void onDisconnect(ConnectionError);

	virtual void handleMessage( const Message& msg, MessageSession * /*session*/ );

	virtual void handleChatState( const JID& from, ChatStateType state );

	virtual void handleLog( LogLevel level, LogArea area, const std::string& message );

	virtual void handleVCard( const JID& jid, const VCard *v );
	virtual void handleVCardResult( VCardContext context, const JID& jid,
				StanzaError se = StanzaErrorUndefined  );



    void chatMessage(JID& jid, std::string& msg);
    void lookVcard(JID& jid);
    void chatGroup(JID& jid, std::string& msg);
    void downloadOrgZIP();
    void compressOrg();
    
    void registerConnect(WhLoginViewController* connectHandler)
    {
        _loginViewController = connectHandler;
    }
    
private:
    
    gloox::Client*    _client;
    gloox::JID*       _jid;
    MessageSession*   _messageSession;

	std::string       _domain;
	std::string       _userJid;
	std::string       _password;
    
    WhLoginViewController*     _loginViewController;
};

#endif /* defined(__IOSDemo__Connect__) */
